package com.secondhand.service.Impl;

import com.secondhand.domain.order;
import com.secondhand.mapper.goodMapper;
import com.secondhand.mapper.orderMapper;
import com.secondhand.service.orderService;
import com.secondhand.vo.orderItem;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Log4j2
@Service
public class orderServiceImpl implements orderService {

    @Autowired
    orderMapper ordermapper;

    @Autowired
    goodMapper goodmapper;
    /**
     * 生成订单
     *
     * @param orders
     * @return
     */
    @Override
    public boolean generateOrder(order orders) {
        ordermapper.generateOrder(orders.getSellerId(),orders.getBuyerId(),orders.getGoodId());
       //修改商品为不可见
        goodmapper.updateGoods(orders.getGoodId());
        return true;
    }

    /**
     * 获取已经卖出的物品订单
     *
     * @param userId
     * @return
     */
    @Override
    public List<orderItem> getSold(int userId) {
        List<orderItem> result = ordermapper.getSold(userId);
        return result;
    }

    /**
     * 获取已经买到的物品订单
     *
     * @param userId
     * @return
     */
    @Override
    public List<orderItem> getBought(int userId) {
        List<orderItem> result = ordermapper.getBought(userId);
        return result;
    }

    /**
     * 获取待签收订单
     *
     * @param userId
     * @return
     */
    @Override
    public List<orderItem> getHalfSoldOrder(int userId) {
        List<orderItem> result = ordermapper.getHalfSoldOrder(userId);
        return result;
    }

    /**
     * 获取待收货订单
     *
     * @param userId
     * @return
     */
    @Override
    public List<orderItem> getHalfBoughtOrder(int userId) {
        List<orderItem> result = ordermapper.getHalfBoughtOrder(userId);
        return result;
    }

    /**
     * 发货
     *
     * @param orderId
     * @return
     */
    @Override
    public boolean send(int orderId) {
        ordermapper.send(orderId);
        return true;
    }

    /**
     * 收货
     *
     * @param orderId
     * @return
     */
    @Override
    public boolean receive(int orderId,int goodId) {
        ordermapper.receive(orderId);
        //修改商品状态为已卖出
        goodmapper.goodBoughtState(goodId);
        return true;
    }
}
